package es.mahulo.battleship.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 * A shot in the board is represented with two coordinates (x,y)
 * 
 * @author mhuertas
 *
 */
@XmlRootElement


@Entity
@Table(name="SHOT")
public class Shot {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name="ID")
	private Long id;

	/**
	 * Coordinate x of the shot
	 */
	@Column(name="X")
	private int x;
	/**
	 * Coordinate y of the shot
	 */
	@Column(name="Y")
	private int y;
	
	@ManyToOne
	@JoinColumn(name="ID_PLAYER")
	private Player player;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}


	public Shot() {
		super();
	}
	
	public Shot(int x, int y) {
		super();
		this.x = x;
		this.y = y;
	}
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	@XmlTransient
	public Player getPlayer() {
		return player;
	}

	public void setPlayer(Player player) {
		this.player = player;
	}

	public String toString() {
		return "Shot { Id: "
					+ id 
					+ " player: " 
					+ player 
					+ " x: " 
					+ x 
					+ " y: " 
					+ y
					+ " } "; 
	}

}
